{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Einops tutorial, part 1: basics\n",
    "\n",
    "<!-- <img src='http://arogozhnikov.github.io/images/einops/einops_logo_350x350.png' height=\"80\" /> -->\n",
    "\n",
    "## Welcome to einops-land!\n",
    "\n",
    "We don't write \n",
    "```python\n",
    "y = x.transpose(0, 2, 3, 1)\n",
    "```\n",
    "We write comprehensible code\n",
    "```python\n",
    "y = rearrange(x, 'b c h w -> b h w c')\n",
    "```\n",
    "\n",
    "\n",
    "`einops` supports widely used tensor packages (such as `numpy`, `pytorch`, `chainer`, `gluon`, `tensorflow`), and extends them.\n",
    "\n",
    "## What's in this tutorial?\n",
    "\n",
    "- fundamentals: reordering, composition and decomposition of axes\n",
    "- operations: `rearrange`, `reduce`, `repeat`\n",
    "- how much you can do with a single operation!\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Preparations"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Examples are given for `numpy`. This code also setups ipython/jupyter\n",
    "# so that numpy arrays in the output are displayed as images\n",
    "import numpy\n",
    "from utils import display_np_arrays_as_images\n",
    "display_np_arrays_as_images()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load a batch of images to play with"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(6, 96, 96, 3) float64\n"
     ]
    }
   ],
   "source": [
    "ims = numpy.load('./resources/test_images.npy', allow_pickle=False)\n",
    "# There are 6 images of shape 96x96 with 3 color channels packed into tensor\n",
    "print(ims.shape, ims.dtype)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAIAAABt+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FTkSuQmCC\n",
      "text/plain": []
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# display the first image (whole 4d tensor can't be rendered)\n",
    "ims[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAIAAABt+uBvAAAEc0lEQVR4nO2cS0wTURSGZ/oAS2gxIkpLK6SgsqBGaEREMRobnxETBTS+mhh14U6BhRtNE1cmBo0rIxoTRDe6Qkk04gN5GIpYCEEBY6xOMdEiPoBWoeCCjUbpuaP3Ucn5tj1z5s+XO7czt70jD0wOSMj0aEQHiHV0Qs7a/7z/WvW1xw2PFb8SDoWTU5IdeY6N2zbu2LtDH6cXEmk6ZM6X2Pdv308ePVlzoWZiYuL3T9MWpJ29cnbl2pU8I0WHq6BwKFzmKmtvaY9So9Vqz1w6U+Yu45YqOlznoPKD5dHtSJIUiUQqD1V6m718IoHwG0E+r29z/mbC4qXLlta31TPNQwi/EVR7sZa82Of1dT/rZheGHH6Cmu83q6pvvNfIKIkq+AkKvAmoqldeK4ySqIKToNGR0bGxMVWHfBr6xCaLOjgJMiQYdDp1N6WmJBOjMKrgJEiWZbPVrOoQa7qVURhV8JuDVq1bpaq+yFXEKIkq+AnafXA3ebEjz7HEuYRdGHL4CXIWOIt3FpNU6nQ6T5VHlmXWkUjg+qhRdbkqb3le9BqNRnP6wumC1QV8IoFwFWRIMNx4cGPPoT0azZ/Pa7aar9+5vuvALp6posN7uWOKvp6+2ou1TfebAv5AKBRKTkl25Do2bNtQsq8kLj6Of54oiBH0H4FLrgAoCAAFAaAgABQEQO1nn3fKO6fNSavbFHWtdc4Cyj3VgiMIAAUBoCAAFASAggBQEAAKAkBBACgIAAUBUHvUMFvNhGtvH4Mfc1JyaJ2XNTiCAFAQAAoCQEEAKAgABQGgIAAUBICCAFAQAAoCQEEAKAgABQGgIAAUBICCAAQIipH/9xIiQJBWq+V/0r9GgCCdnnQhPDIeYZqEBAGC4mfFE1aODI8wTUKCmEss0ZhIUhl8H2QdBkTMt9jsObNJynq7exkHgREjaL5lPklZy8MW1klAxAgi3Czn8/pevnjJOkx0xAiyL7QTVnrKPUyTgIgRlO3IJqxsqG84fuQ4uCF4fHz80d1HlYcr3Vvd/5zuF8RsZlH8Sn5GPnl9RmaG+4i7aF2RxWYxJhnDofDXz18DbwPKa6Wnq6fjSYfP65u6JzCajL2faU7twnb7rMhc4X/lZ9G5Q+lITUul1U3Yw+r64vWMOvf19FHsJkxQ6f5SRp1niKCc3BxGG1P7n/dT7CZyPajCU8Gi7QwZQZIkFa4pLNlXQr3tzBEkSdKp86eysrPo9hwaHBr8MEirm2BBpiRTze0ai81Cty3FQSR+TTrdnn6r9RbFF1Ho4/QUF5LEC5IkKTUtta61rsJTYUgw/Esfi81y7MQxr9/r2uKilS229s0H3werz1XfvHpT1euqbBk21xbXpu2bCtcUTvdOh78mtgRNMTk52fW0q62prbO90//KP/B2YPjLcGg0JMtyoinRaDLOnTfXvsieuTgzKzsrNz+X+hT2M7EoKKaIiTkolkFBACgIAAUBoCAAFASAggBQEAAKAkBBACgIAAUBoCAAFASAggBQEAAKAkBBAD8ASE42MDbjHwUAAAAASUVORK5CYII=\n",
      "text/plain": []
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# second image in a batch\n",
    "ims[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# we'll use three operations\n",
    "from einops import rearrange, reduce, repeat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAIAAABt+uBvAAAGcElEQVR4nO2ce0yTVxiHT4ctLb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jnLErNnwAAAABJRU5ErkJggg==\n",
      "text/plain": []
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# rearrange, as its name suggests, rearranges elements\n",
    "# below we swapped height and width.\n",
    "# In other words, transposed first two axes (dimensions)\n",
    "rearrange(ims[0], 'h w c -> w h c')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Composition of axes\n",
    "transposition is very common and useful, but let's move to other capabilities provided by einops"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGAAAAJACAIAAAD9yfRwAAAfU0lEQVR4nO2dd1hU17qHN21gYOgqvUhRg6IokogiYhcRNBY0RmM5Ro+mmCsaT2KiISYaTTwaxXRJVDQSK1FREQ2gYgERUOkWYOhIG2CoM/cP7uPNUeBbM6w1hfO9T57zR843v7V4s2fP3mvtvZaGtLiYQ7pGU9kdUHVQEAAKAkBBACgIAAUBoCAAFASAggBQEAAKAkBBACgIAAUBoCAAFASAggBQEAAKAkBBACgIAAUBoCAAbSW23dzScjslJeHWrfTMzNzHj4vLyuobGppbWvh6evp8fh8zs/729k729l4eHqNHjnR2dFRKJzUUP3EolUovxcVFnDwZdelSfUMD4adc+/cPDgpaEhzs2r8/0+69gEIFSSSSwydO7Ni/PzM3V74ETU3NOQEBW9atGzxwIN2+dYXiBN1OSXnn44/vpqf3PEpHRydk1aotISF6uro9T+seRQiSSCTb9u79bNeu9vZ2irEjhw07HR5ua2VFMfNlmAtqFIvnrVwZfeUKi3DLfv3iTp4c6OzMIrwDtj/z1bW1k4KDGdnhOK60vHzivHlPCgoY5XNMBTU1NwctWXLz7l12TXAcV1RaOnPZMnFTE6N8hoIWv/fe9Tt32OU/535m5gebNzMKZyVo/6+/njh3jlH4y/wUEXEjKYlFMpOTdFZe3ogpU9gd9p0yfMiQu5cuaWho0I1lcgSt/fRTBdvhOO7eg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+PBRYWFZUVF5eXlVY2NTc3NrS0urlpYmj6ejp8czMTHs08fEwsK8f39rFxc7d3dXLy83AwO+wvr5d1R0TFp1UOkhV1UABQGgIAAUBICCAFAQAAoCQEEAKAgABQGgIAAUBICCAFAQAAoCQEEAKAgABQH8L/2OoNUQbH9iAAAAAElFTkSuQmCC\n",
      "text/plain": []
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# einops allows seamlessly composing batch and height to a new height dimension\n",
    "# We just rendered all images by collapsing to 3d tensor!\n",
    "rearrange(ims, 'b h w c -> (b h) w c')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAkAAAABgCAIAAAB6y1p+AAAc2klEQVR4nO3dd1hTZ9sA8LAJhI3sJUMUBRGwyhBwgaiAE3cR3qpVXBVXa4XirForVqytgzrQiqIUQVCKClRwMGQo2wGEjawACSv5/uD9vPrWEp4k55ycxPt3efWP+uR+7p4muXOe8wwJTm0tBQytTlfYGZAcXCCu4PJwZ5cr7AxIDi4QV5LCTgAAAADgh7SwEwD/ory4/Nr5a389+IteSWcxWRojNKztrGf5zlq4cqGMrIywswMAAFKQgCFE7ggeAurt6Q39KvTKr1fYbPbHf6tvpB9+Mdx5qjOhOXEHY2RcweXhDkbIhgEXiCsYQiQRFpO1aNqiS2cu/Wv1olAoNVU1S2cuvXHpBsGJAQAACUEBI5HgL4KzM7O5txkYGNixZkdWRhYxKQEAAGlBASOLvKy82GuxKC37+vpCvwrFOx8AACA5KGBkcfXcVfTGeVl5L1+8xC8ZAAAgPyhgZJHxMIOn9ukp6ThlAgAAIgEKGFnUVNXw1J7+jo5TJgAAIBKggJFCd1d3X18fTy9pa23DJxcAABANUMBIgapAlZbmbVG5sooyTskAAIBIgAJGChISEroGvC15NTA2wCkZAAAQCVDAyMJlugtP7afMmIJTJgAAIBKggJHF8i+Woze2trO2sb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8ra6trOjk5mN1NCQoKmTFNSVtLU0jQdZWpmaWY+2nzCZxMwf4T2P0h4gchEiJfnXUlJTlpaSW5uVXl57du3ne3tzK4uNptNVVRUoNF0jIyMRo2ysLa2c3MbPWECVsOPvBJuAdPR+O8PoOqG6j+f/plbkltQXlBVX9XGaOvs7pSXk1dSUDLQNhgzcoz9GPtZTrMsjQn9dqZQiChgHzAY3S9elOTllb169bq6uqGmprGxsaW7m9XT09fb2yclJSkrKyMvL6uqqqSpqaqtrTFypJ65uaG1tcXEiVa4DkhyIfwCRnLw/TwMuEBcweXhjiQFjLwILGCiiLhnYAAAAACGoIABAAAQSVDAAAAAiCQoYAAAAEQSFDAAAAAiCQoYAAAAkQQFDAAAgEiCAgYAAEAkQQEDAAAgkqCAAQAAEElQwAAAAIgkKGAAAABEEhQwAAAAIgkKGAAAAJEEBQwAAIBIggIGAABAJEkLOwEAAMCMg5UDJ4cj7CwAQeAODAAAgEj6P305csU5cKRnAAAAAElFTkSuQmCC\n",
      "text/plain": []
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# or compose a new dimension of batch and width\n",
    "rearrange(ims, 'b h w c -> h (b w) c')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(96, 576, 3)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# resulting dimensions are computed very simply\n",
    "# length of newly composed axis is a product of components\n",
    "# [6, 96, 96, 3] -> [96, (6 * 96), 3]\n",
    "rearrange(ims, 'b h w c -> h (b w) c').shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(165888,)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# we can compose more than two axes. \n",
    "# let's flatten 4d array into 1d, resulting array has as many elements as the original\n",
    "rearrange(ims, 'b h w c -> (b h w c)').shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## Decomposition of axis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2, 3, 96, 96, 3)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# decomposition is the inverse process - represent an axis as a combination of new axes\n",
    "# several decompositions possible, so b1=2 is to decompose 6 to b1=2 and b2=3\n",
    "rearrange(ims, '(b1 b2) h w c -> b1 b2 h w c ', b1=2).shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASAAAADACAIAAAAr0inhAAAdO0lEQVR4nO3dZ1hUV7cH8KEzMENXepFiQVEEjYIIVhAVNBbsQUzUWKLGnqAQNGrUGDFiiUYSFYkFC4KgCAaIYKFIUbqFXqUNMEObuR+8N/d9VWDPzN5niuv35MmHuFhnBfkzZ+bss48Mr6KCBnpWqS/qCcQcfIN6JSvqAQCQZvKiHgB8RGFuYejvof/E/VNWXMZhc7T7advY2UybNW3u0rkKigqing7wQQZOEXtH8RlQR3uH/7f+F3+7yOVyP/xTQxPDwD8Dx00cR+lMvYNTxF7BKaIY4bA58ybNO3/q/EfTRaPRykvKF05dePX8VYoHAwKDgImRLV9tSU1O7b2mu7t728ptKUkp1IwEhAQBExcZKRk3Q2+iVHZ2dvp/6096HoAFBExcXDp7Cb04IyXj+bPn5IYBuEDAxEXSgyS+6hNjEwlNAjCCgImL8pJyvurL3pQRmgRgBAETC22tbZ2dnXx9SWNDI5lZAE4QMLFAV6HLy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0mQpo9e8KjR3/q6WmTOwQV75Gshg+/nJm5dPNm9CfB9m7SnDlhOTlOM2Zg6SatPJw9UkNSJShdNBpNS0vt6dMLjx+f9/HxVFUluHORiYleaOi+mzePqKmRfW2nImA0Gk1ZReXbI0euZGVN9fIS5lKMrZPTbw8eHL5+XVuvt6eDS4epY6YK9rmfvo7+xb0Xbx+9rcHUwD0UFcaMGRYc7F9ZGfP777udne3wXruztR3022++hYW3Fi0S/Am06PCv5OhTaVHR7T/+iAoJQX9Eg5qm5lQvL08fn2FjxhCd7UMiXMlRGVPJ5XLPhZ8Liw3LKsxC+RJrc+t1Xuu8Z3pT96aLwEqO95SUVF27FhsZmZiUlNnZ2ePK1V7Iycna2g6aMcPp888nkn7q+XtEELB/vcnLS0tIyEtPLyksrHj9uqWpid3ayuVy6aqqKgyGnomJycCBVjY2di4ug0eOxHV6yS/RBkxP+39fqEurS+8/vp+el55VmFVSVdLIamxpa1FWUmaqMI10jYYMGGI/xH6a4zQR7AVAPmD/YrHanj3Ly8goePHiZWlpdXl5TU1NfVsbp729s6OjU05OVlFRQVlZUUODqaOjoaurPWCAgaWlsY2N1ejR1kRPOHshyoBJBDEJmPiiMGCSiKL3YAB8miBgABAEAQOAIAgYAARBwAAgCAIGAEEQMAAIgoABQBAEDACCIGAAEAQBA4AgCBgABEHAACAIAgYAQRAwAAiCgAFAkARs9SplRlmP4qXBTa6fCngFA4Cg/wHxB2E1+GWrPAAAAABJRU5ErkJggg==\n",
      "text/plain": []
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# finally, combine composition and decomposition:\n",
    "rearrange(ims, '(b1 b2) h w c -> (b1 h) (b2 w) c ', b1=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMAAAAEgCAIAAABtjetmAAAdt0lEQVR4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UHq9VrDkYmMyePeHevd+NjJDW9UoGCMQoenpaDx+eun//ZHCwn6Ymi76GLCyMoqK2X768V0tLk75WKBBIKowaNTQiYmtFRcKvv24ZN24k2ZO8nJ0dfvllU2HhnwsWSL5DHjrQEy01OByNTz+d/emns0tKKi9cSIyLS7l7N7Ojo1OCVEpKis7ODjNmeH700US6d9XsBo1HXvYPmDzyksdrffIkLyOj4Nmz56WlVWVl1dXVda2tgra2jvb2DiUlRVVVFXV1VR0djoGBjqGh/qBBJra25k5Odm5ujrTeEHsBBOoDhs9MlTvgGQjAAgQCsACBACxAIAALEAjAAgQCsACBACxAIAALEAjAAgQCsACBACxAIAALEAjAAgQCsACBACxAIAALEAjAAgQCsPhfPLVVQZtx0KkAAAAASUVORK5CYII=\n",
      "text/plain": []
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# slightly different composition: b1 is merged with width, b2 with height\n",
    "# ... so letters are ordered by w then by h\n",
    "rearrange(ims, '(b1 b2) h w c -> (b2 h) (b1 w) c ', b1=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASAAAADACAIAAAAr0inhAAAoR0lEQVR4nO2dZ1wVx9fHD1VQQREFBAEL1liI2Fs0djSEqNgbamxRo7ElRoOaRBNLNNHEGKNg16CgYsGCUUCxAAoq2FCQZqdJh3ufF+S5f7I7u3dmdxYuN/P95EU4zO4e7+Xsb3fmzDkG6rQ00CXS61e2Bxx0zCEdcwfaR1e2Bxx0zCHDynaAwdBnWIAxGArCAozBUBC9CrBVC1e1sGrh5uh2aNehyvaFwQDQpwB7FP8oLCSsIL+gTfs2w8cPr2x3GAwAfQqwXVt2xcXEFRUWnTtxzrma85W/r1S2RwyGvgRYUWHR3u17NT86ODl079O9Ev1hMMrQkwBTqVQqlUrzY+qzVEdjx0r0h8EoQ08CbGS/kRzLxp0bK8UTBqM8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5qa1K5tYWtr7eLi2LGjrD9jCgpGFx0TDJ1zSMfcoaNgNJGkYMqhVHIng1Eeog6X+gQLMEZFIL/DZRWFBRijImAKxmAoCFMwBkNBmIIxGArCFIzBUBCmYAyGgjAFYzAUhCkYg6EgTMEYDAVhCsZgKAhTMAZDQZiCMRgKwhSMwVAQpmAMhoIwBWMwFIQpGIOhIEzBGAwFYQrGYCgIUzAGQ0GYgjEYCsIUjMFQEKZgDIaCMAVjMBSEKRiDoSBMwRgMBWEKxmAoCFMwBkNBmIIxGArCFIzBUBCmYAyGgjAFYzAU5D+rYGLN1RkMWnRo1YF+M8uqAFMwBkNBWIAxGArCAozBUJD/A4guTiHH3Bo2AAAAAElFTkSuQmCC\n",
      "text/plain": []
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# move part of width dimension to height. \n",
    "# we should call this width-to-height as image width shrunk by 2 and height doubled. \n",
    "# but all pixels are the same!\n",
    "# Can you write reverse operation (height-to-width)?\n",
    "rearrange(ims, 'b h (w w2) c -> (h w2) (b w) c', w2=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Order of axes matters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAkAAAABgCAIAAAB6y1p+AAAc2klEQVR4nO3dd1hTZ9sA8LAJhI3sJUMUBRGwyhBwgaiAE3cR3qpVXBVXa4XirForVqytgzrQiqIUQVCKClRwMGQo2wGEjawACSv5/uD9vPrWEp4k55ycxPt3efWP+uR+7p4muXOe8wwJTm0tBQytTlfYGZAcXCCu4PJwZ5cr7AxIDi4QV5LCTgAAAADgh7SwEwD/ory4/Nr5a389+IteSWcxWRojNKztrGf5zlq4cqGMrIywswMAAFKQgCFE7ggeAurt6Q39KvTKr1fYbPbHf6tvpB9+Mdx5qjOhOXEHY2RcweXhDkbIhgEXiCsYQiQRFp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XFwc7e2lMPrt+TFh7cTxr5obm8+fPH8r6lZNVQ36qwxNDGfMmeG1wMvJ3Qn7Z/6wEwdXxL9/qisq7vz2W2JUVD3yJ0tZTW2mn59PQMC4SZNwze1jQtyJoy65js1mX4i7EJMSU1BegPISK1OrIL8g/7n+xD30wmEnjn+oqqq/eTMlISE9IyO/r2/InTO5kJKStLW1nDPHZf78qYg702NFOAXs76pra/Nevcp/9arszZua+vqaurrW9nYmi8VksTgcjqKCwuCmiEo0mpG+/mhz88E/NlZW8nJIp6gJiFQFbBCHwynIKXj++Hl+dn7lm8ra6trOjk5mN1NCQoKmTFNSVtLU0jQdZWpmaWY+2nzCZxMwf4T2P0h4gchEiJfnXUlJTlpaSW5uVXl57du3ne3tzK4uNptNVVRUoNF0jIyMRo2ysLa2c3MbPWECVsOPvBJuAdPR+O8PoOqG6j+f/plbkltQXlBVX9XGaOvs7pSXk1dSUDLQNhgzcoz9GPtZTrMsjQn9dqZQiChgHzAY3S9elOTllb169bq6uqGmprGxsaW7m9XT09fb2yclJSkrKyMvL6uqqqSpqaqtrTFypJ65uaG1tcXEiVa4DkhyIfwCRnLw/TwMuEBcweXhjiQFjLwILGCiiLhnYAAAAACGoIABAAAQSVDAAAAAiCQoYAAAAEQSFDAAAAAiCQoYAAAAkQQFDAAAgEiCAgYAAEAkQQEDAAAgkqCAAQAAEElQwAAAAIgkKGAAAABEEhQwAAAAIgkKGAAAAJEEBQwAAIBIggIGAABAJEkLOwEAAMCMg5UDJ4cj7CwAQeAODAAAgEj6P305csU5cKRnAAAAAElFTkSuQmCC\n",
      "text/plain": []
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# compare with the next example\n",
    "rearrange(ims, 'b h w c -> h (b w) c')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAk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aaSjKJVRq3r1/Uv3KyoqdO3QoaZOTQBKysqTB01WV1dtaGIyf9V8AAqKih1bdNTW1tKpWZN7q9WoWtVIz8jY2EBTQ+NKwBUAOgYGVTWq/vRTE0VFRdfNrgAsra0VKiv07t1JQUGh//D+AHqNHl1Frcq0aUO0NDVbWbcCMHPDBt0aulu3ztGvXVuvjh6AwwEBVuZWt2/vbWBsrKmluXv38VsfP47sOTIpyaeVpaWiomJMTN7C3bvdZrsFBh75xcFBSUkpJiavaZs2L868cHWdsGDq1Oo1qnM/+X9P/du8ecNDW7bUrV+XM5MGTgLgf+lSyzYtOVNFrQqAxNBQx5GOkv8Sbnt6zls5T9IsnTVrn+c+SdPhp58C3wRKGgUFBf9If+Zf1KrtqxjToWsHxlSuXNnN7SCIigTVQiTkEU1NdXwuYDp1aomC3cemTRvCmD17FjHm8uWtvKnXqBHevg8OPs6bAc7OCEJs7HXE6nFu0Z49CEJSkg9v9nh5IQjp6fd5cyEy0jAIubmBvLn9338tgzDWtTlv/DIyWgZh+4mxvHmQldUyCGgZhFi92EoA4J2YmG/0gFhciY5mzIF79xjjevDghWkH0TJoy/xNnBnh4rLJxgUtg6Y6zuSMuZVVwOEAtAwKvXuXM5UVFDyWe6BKUODVq5wBMH3odCDozP79vGlo1BAIWr1gwdStCyR/kqMGDrSdNlDS/NSixUW/i5JGVUVlq8dW5uc/fdF0xvQc0JMx+ob6jCGIIkIrMIIgCEKQUAAjCIIgBAkFMIIgCEKQUAAjCIIgBAkFMIIgCEKQUAAjCIIgBAkFMIIgCEKQUAAjCIIgBAkFMIIgCEKQUAAjCIIgBAkFMIIgCEKQUAAjCIIgBAkFMIIgCEKQUAAjCIIgBAkFMIIgCEKQUAAjCIIgBAkFsAqHlTnblznvIdtPubwa3Rq6IAiivEABjCAIghAk/wPn2aSnaEtA3gAAAABJRU5ErkJggg==\n",
      "text/plain": []
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# order of axes in composition is different\n",
    "# rule is just as for digits in the number: leftmost digit is the most significant, \n",
    "# while neighboring numbers differ in the rightmost axis.\n",
    "\n",
    "# you can also think of this as lexicographic sort\n",
    "rearrange(ims, 'b h w c -> h (w b) c')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAkAAAABgCAIAAAB6y1p+AAAdFUlEQVR4nO3dd1hT1/sA8MsmEDaylwxRFESBKoi4QVTAibsI36pVXBVXa4XirFq/YsXaOqgDqShKEQSloEAFB0OGsh2BsJEVIGElvz/4Pj79aQknyb03Cbyfp0//aN+85xVD3txzzz1HglNdjYGB5ejqCrsEkaaL1Qi7BJGmmwPvH25q4MfDla5ujrBLEGmSwi4AAAAA4Ie0sAsAgGdlRWURlyL+Tv6bTqOzmCyNERrWE63nes1dsmaJjKyMsKsDAJBEAqYQuYMpRO5InkLs7uoO+ibo+m/X2Wz25/9X30g/5ErIlBlTyCyJO5hC5A6mELmDKUTuYAoRiA0Wk7V05tKr56/+a/fCMKyqomrFnBW3rt4iuTAAgFBAAwNiI+CrgKyMLO4xfX19u9fvzkzPJKckAIAQQQMD4iE3Mzc6IholsqenJ+ibIKLrAQAIHTQwIB5uXLyBHpybmfvq5SviigEAiAJoYEA8pD9K5yk+LSmNoEoAACICGhgQD1UVVTzF09/TCaoEACAioIEBMdDZ0dnT08PTS1qaW4ipBQAgKqCBATFAUaBIS/P20L2yijJBxQAARAQ0MCAGJCQkdA14e+TVwNiAoGIAACICGhgQD86znHmKnzp7KkGVAABEBDQwIB5WfbUKPdh6orWNnQ1xxQAARAE0MCAe7CbbeS73RImUlpYOPh0sISFBdEkAAOGCBgbExumw0xMnTeQeIykpeeK3E5NdJpNTEgBAiKCBAbFBUaBEPY5avX61pOS/v291DXT/ePjHCr8VJBcGABAKOE5lEHCcCndCOZG5tLD0xsUbTx49qaJVMZlMjREa1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G5va2d2MiUkJKjKVCVlJU0tTdNRpmaWZuajzSd8MQH3W2j/JNwGpqPxvw/oyrrKv579lVOck1+WX1Fb0cJoae9sl5eTV1JQMtA2GDNyjN0Yu7lOcy2NSf30wQhoYEMMCQ3sIwaj8+XL4tzc0tev31RW1lVV1dfXN3V2srq6erq7e6SkJGVlZeTlZVVVlTQ1VbW1NUaO1DM3N7S2tnBwsCJ0QpIL4TcwESfEBiYWRLCBiRQRaWAiCxoYd2Q2MHFE3j0wAAAAAEfQwAAAAIglaGAAAADEEjQwAAAAYgkaGAAAALEEDQwAAIBYggYGAABALEEDAwAAIJaggQEAABBL0MAAAACIJWhgAAAAxBI0MAAAAGIJGhgAAACxBA0MAACAWIIGBgAAQCxBAwMAACCWpIVdAACAB/ZW9pxsjrCrAEAkwBUYAAAAsfR/yZt6v0TttqAAAAAASUVORK5CYII=\n",
      "text/plain": []
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# what if b1 and b2 are reordered before composing to width?\n",
    "rearrange(ims, '(b1 b2) h w c -> h (b1 b2 w) c ', b1=2) # produces 'einops'\n",
    "rearrange(ims, '(b1 b2) h w c -> h (b2 b1 w) c ', b1=2) # produces 'eoipns'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## Meet einops.reduce\n",
    "\n",
    "In einops-land you don't need to guess what happened\n",
    "```python\n",
    "x.mean(-1)\n",
    "```\n",
    "Because you write what the operation does\n",
    "```python\n",
    "reduce(x, 'b h w c -> b h w', 'mean')\n",
    "```\n",
    "\n",
    "if axis is not present in the output — you guessed it — axis was reduced."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAIAAABt+uBvAAAM50lEQVR4nO1cWXMbV3a+ve/dWIiFBLiAEkHRkjIzkq3Y1qRm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6WiqRlzbKpoAAAAAElFTkSuQmCC\n",
      "text/plain": []
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# average over batch\n",
    "reduce(ims, 'b h w c -> h w c', 'mean')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAIAAABt+uBvAAAM50lEQVR4nO1cWXMbV3a+ve/dWIiFBLiAEkHRkjIzkq3Y1qRmPDXOL0jVvEzlIQ/5OXlM3lKVh1SlkockldSU4/F4XOXKWIqtsWRLshaLIsAFG7H1vt7OA2haEonuBnUBMxV8T0D3wcXpD3c595zvAuv1emCO8cB/aAfOO8gf5Ftdxx32h6ZheJ4fhiFBEAzLiLIoKzKGYT+IS+OAzXiIhWHYbraH/SEIT7lLUmSxVOQFfpYuRWOmQwxCuLuzO+ydzg4AwPf8vdqeOlBn6VU0ZkpQ66Blm3aMUQiaB03LtGbiUTxmR5Bt2dpQS2Qagk6zPWV3kmJ2BA37w+TGtuU4dlxfmwlmR5BpmBPZG/pk9lPC7AjyPG8ie9/zp+TJRJgRQRDCcSvXOARBMB1fJsOMCMJxHEwYAOLEuYjyZ+cESU0WtVMUNSVPJsLsCJo0Pj4n8fTsCFLSSnJjhmNYjp2eM8kxO4I4jpMUKZEpBvKF3JTdSYqZToSFpUJ8v8BAYanAnY/xBWZMEI7j5bWyklbGrWgkRZZXy0pqgsE4bcw63TGC6ziD/tA0TN/zIYQESbAsK0qinPp/nw/6P4dzEYydZ8wJisGcoBjMCYrB7KoaMISmZZqWYVmmZVumbXY6nefPtvf299utTq/X0zTNtm0IQ4qiWJbLpLP5fKG0VNq4uLmxUc2kUzRN0TTFMDRJEjNzGxlBvudvP9l+8UoAg4E66A97A7WvagPN0GAAQxCqA+3xN08ePXzUarVhGJUEWa4scxwHAKAoamPj0p++9e61H7/J8wJNkzzPiiIvihxBTJcsZMv8M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7drZXDaVSfW7fXWo+S8rz3CCyC8WF5eXyuXSUqGYElMEQXAsK/C8wPOKLAmSKMlicXEpm8+ifQr0BLEsW91849RbEIa25di26ziu5/nLC2XbsFRVVYdqr9/t9ruaruq5fAADx3E83ydJUhCETDaTz+dFXkjLaUWSOY7lOV6SRYZhaIbmOA7hxuIkZvpXpTiO8QLLC0fTzebqhWhB1HnA/Fh4DOYExWBOUAzmBMVgTlAM5gTFYE5QDOYExWBOUAzmBMVgTlAM5gTFYE5QDOYExWBOUAzmBMVg/lelMZj3oBj8L6WiqRlzbKpoAAAAAElFTkSuQmCC\n",
      "text/plain": []
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# the previous is identical to familiar:\n",
    "ims.mean(axis=0)\n",
    "# but is so much more readable"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAAAAADH8yjkAAAC6klEQVR4nO3ZTWgTQRQH8NmY1iakAY1aE0PVNipSArYKtrZWBKW96KlgsQePCnoVvJVCPehFEbyoF9EqguBB9KYUW0WhgSIYaRWx2mhTsa3U5oONqwcVsxP/k3mbmUNh55Q383Z+2Z3d2dldI8H0Fo/m/plXMu/7rZHpXCjevY8KGHKH6NIN6/ePDRcbaIDcITp+/U//LNU7ogEYHPv3+8fpaeVA+l5xZPYrB4bs4fhX1cBTLn6iGkhxMWkQZACTixdUA/zFGFQNhLk4qhro4OK9qoGj9jC+TjUQOVwceQco/ctNFf0tRRuc36geYFf7/uaFbxMnbMnpmi0OjaayoXjXflr38oDjov2W6QJli8yqIj/1eTb9JT2fz+dyBeOnt8bn84ej0WhstcTG+CzaWX7jSEvbnnJTa0UAY6yqvafVECVUOgbm8Kn7wgQFg1yvG2jUDNTVagbKnKuVA68vaAbYzQnNABu0BI0qgOQDR0AisVtWuMKv/aQA9vIFaunh4k8PHQF3YMuxTq7irhPg2yO81TlufkviEwkDw4IDW93OVTx2AuD+GTvAxfiZBALWGGphrPRmMblABt5lRECEr0iSgVei/hlbJQvAm/4HQe+HSqs+oly4BzMCgJIOgTQNmCUDwjEuLVkykKMBMB0CBRoAL3sIrKQBMF0VUEMGAjQApkOgjgbAdAispwEwHQKbacAmMrBd0NvW0qomMlAvGOWTZ/n16IptZMBoxcBE9zXuLN7hIwOilzbPWKzLXtMMczHQWQ2bxpesOXvNLpiLnzKDB/GKcGDtqC0O4D0QPMYewQC/ZGrD3QhWdk384geX57hJtLo+IQ0sOgMI5Y0jYF4emHQE4L9FSFUEONuDt5qBwpQ8gIdLAGT+MyvD8t4BEDwj33/VEmqR/Y4mLJHePtim5ELrwP0T9mDLXM40PR7LxzKG35/JGoHaNQ2NsWbh+y4KcDkknVpclv97UxdwARdwARdQUZb/p8ZfQUuUaec5TOsAAAAASUVORK5CYII=\n",
      "text/plain": []
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Example of reducing of several axes \n",
    "# besides mean, there are also min, max, sum, prod\n",
    "reduce(ims, 'b h w c -> h w', 'min')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASAAAAAwCAIAAAA+QDD4AAAOvUlEQVR4nO2deVgTdxrHJxJyEO4QIoQjhYKgIKAWWATEA6wgUhGtugW6UqvtbmnFum1XWqju1hYU0N1aRC1gK9rHopWjCFqKUkQTuUHCJSDlTghXDgiQ/cNn+8jMQGfCJGHT+Tz89ead3/t9Mrzzu97fhCDv6QEWE71m6lYAYpEJWmRygFWV6lYAYpEJWqJuAdgwMzNz4fQFX0dfa5K1G8stNjp2RDiiblE4OABBM3qwmKiYq19ffd5iv9w+536OvoG+egQpjUUmZ7F1GItOkCb0YDWPakDZBQBA8+PmCykX1KIHB+c3NCHByorLYO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7ceKd1asd5i8DcnKyjYt7s7X15rFjbyEfHD5job/RLJ2YaGhqamlv7+3vF0kkAADo6ugYGRjY29g42tsbos8rrH6DWC6Xt/Ja6yrr+nr6JiQTVBrVdKmp7TJbBycHMgVNaeUi+1HkhciRiMUNHE4njzcyNCSXy/UMDa3s7Z09PGgLePwhfM9n92C3xcvglbfD4YdPvndSOinl1HManjQIRgTaWtosU5a7k7u9lb1yBc1GIBipqWnu6Ojh84el0sklSwhUKtnExNDa2szZ2Y5ON1BQjMb8CLoSWWSCFpkcDBJMPYJUBf7jDzg4SgRPMBwcJYInGA6OEsETDAdHieAJhoOjRPAEw8FRIniC4eAoEfxFNDiqgMVgyStQvCtGY/gvgG54BWRivlsAAAAASUVORK5CYII=\n",
      "text/plain": []
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# this is mean-pooling with 2x2 kernel\n",
    "# image is split into 2x2 patches, each patch is averaged\n",
    "reduce(ims, 'b (h h2) (w w2) c -> h (b w) c', 'mean', h2=2, w2=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASAAAAAwCAIAAAA+QDD4AAAKVElEQVR4nO2de1BTVx7H7yXxESC8XDEEEMRXHXxUU3xQtLoquLJKR+pr8FkrpWsHq+3UHdtFnWVKFWkZ2bq44666tUoVWhtfGIuP5a1ECMOC7xeS6PAIEpDySM7+4Q6D596Ec27uTWI4n8kf+uN3f+c7mfxyz/md3z2hgVZLORI6P3srgHAwQQ4mh5pyw94KIBxMkIu9BfDJrk93veH9xrqYdV2dXfbWQiBQFEWJ7S2AH35r/y3ENeTlv1VKVdCgoPTD6cvWLrOvKgLBSe5gPdnVwyfrPrGHEALhFZwkwVjZn7rf3hII/R1nSDAAAKv98f3HNlZCIEA4Q4LRNM1qX7lhpY2VEAgQzpBgFEU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     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# max-pooling is similar\n",
    "# result is not as smmoth as for mean-pooling\n",
    "reduce(ims, 'b (h h2) (w w2) c -> h (b w) c', 'max', h2=2, w2=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMAAAAEgCAAAAADHhCPtAAAO0ElEQVR4nO1de1hVVRbfvBS4gBBioKA8QhNFEYdSs8wXPhKTLMtnzWRT42usfPaNzfiNY59YNqZlhuOYlYPkaE6GoCFqxGdCigKG75SHlpoXBLkg3jt/KHXWuWftvc+597oP33d+f91119r7rt89e5/9XtvtF9K64S7aAUdhEBANg4BoGAREwyAgGgYB0TAIiIZBQDQMAqJhEBANg4BoGAREw5PbsqmooOzs5fomb5/gLl0SH4pyticX8ovPnq+5afX1D4/u8Ug87z/rxjexZduXmVUPvolOfS5GpYsUXNyaeRZ8ETRuUl+ulFwErFtXn7L/1j1l4YNcv8HEyXe2W+2/7Td/MEdaHgJF848pK7xmLmzL8RsM3Fz+oYL7hBAyKq0TMzWbgHXVituoMuHTjsyfYODYCxdQnd+aJ1nJmQQaXthLU3fY9QDrJ+jYNruRpn7tL4z0LALmZwvpBmFZXRg/QcUnryLFpwUvraDrGW+rxkkM/8mlyRaGBQ3b5zL8J+l/pesZBF4+xPThxGKmCYqjs2xMmzUZVDW9CG1YwOPG7od5rBRQP6CCw6rtN7RqRn0Cp9/k8mMB+29UxhIe/0njLFoxoxJYxFe8S/Zwmdmh+GM+u8O0QkQrQjkToeyf8njvoHa1v5zYu6sWKAbs4vNEhtQDUPYekdo1rM2lquwdl6EiorANmgmNwGDQAHvMnhPY8tn8zjrwWIuiWc4qoHAElIesDb37qTltFSw1701Bc6EUoYPAf7+MNwN/FQL/vgn0IbZT/ESRDsVZ21r8J55vZEC/NuK5UA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/plain": []
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# yet another example. Can you compute result shape?\n",
    "reduce(ims, '(b1 b2) h w c -> (b2 h) (b1 w)', 'mean', b1=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "jupyter": {
     "outputs_hidden": false
    },
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "source": [
    "## Stack and concatenate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'list'> with 6 tensors of shape (96, 96, 3)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(6, 96, 96, 3)"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# rearrange can also take care of lists of arrays with the same shape\n",
    "x = list(ims)\n",
    "print(type(x), 'with', len(x), 'tensors of shape', x[0].shape)\n",
    "# that's how we can stack inputs\n",
    "# \"list axis\" becomes first (\"b\" in this case), and we left it there\n",
    "rearrange(x, 'b h w c -> b h w c').shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(96, 96, 3, 6)"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# but new axis can appear in the other place:\n",
    "rearrange(x, 'b h w c -> h w c b').shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false,
    "jupyter": {
     "outputs_hidden": false
    },
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# that's equivalent to numpy stacking\n",
    "numpy.array_equal(rearrange(x, 'b h w c -> h w c b'), numpy.stack(x, axis=3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(96, 576, 3)"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ... or we can concatenate \n",
    "rearrange(x, 'b h w c -> h (b w) c').shape  # numpy.stack(x, axis=3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# which is behavior of concatenation\n",
    "numpy.array_equal(rearrange(x, 'b h w c -> h (b w) c'), numpy.concatenate(x, axis=1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Addition or removal of axes\n",
    "\n",
    "You can write 1 to create new axis of length 1. Similarly you can remove such axis.\n",
    "\n",
    "There is also a synonym `()` that you can use. That's a composition of zero axes and it also has a unit length."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(6, 1, 96, 96, 1, 3)\n",
      "(6, 96, 96, 3)\n"
     ]
    }
   ],
   "source": [
    "x = rearrange(ims, 'b h w c -> b 1 h w 1 c') # functionality of numpy.expand_dims\n",
    "print(x.shape)\n",
    "print(rearrange(x, 'b 1 h w 1 c -> b h w c').shape) # functionality of numpy.squeeze"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## Reduce ⇆ repeat\n",
    "\n",
    "reduce and repeat are like opposite of each other: first one reduces amount of elements, second one increases"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
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vXbWNUGZIGAzz+wZs0MR8dbSUnoe7n9W2FW1mfjx8dOn95K4PQrabn16JZ48wYbWhqiNkdNWT2lg9OBdVFEePSoJDp6m7FxwKJFOzIzCyR5w/xbYeHzzz77xspqamJiOoZp3wX7nThQKCsrB/r5hfj7B/j4iHdAc09vb87jx/eys+9mZWXn52P13VPG6Rnofbri0+lR05lmTPRX1VbX3r56Oy057WHGQ2zfrHiAnTgkZGppOWXBguCoKCPkT1ZXe/utpKSU+PiSR49wrY0A6DtxGAcYkynkT8M+jfCPcLJyQnnJs8pnR5KOJKQmyMtDLxRmZkYREf6hod5eXs4qKuJsLtjfP1BY+PzataxLl+4h7kyPFek0sL8zNTZ2cXBwHj7ceuhQppER09hYR1ubRqXSqFQymdzN43F5PG53N4fLrXn5sozFKmOxyioqnv71l6AH6RQ1heTs7jxy7EgnNyeLYRaDTQdramnS1GmvX7/mdnE5XZyW5pbK8soXZS9YZayCvIKG2gZp1wukwMLW1s3Hx9bV1czKavCQIZra2jQNDQqFwu/u5nG5jTU1NeXlFU+fFmRmlhUUEDMjnwAiNbDG1v99ATI1NPX39He1dXW2cjYzMmPQGZrqmoIeAYfHqWuq+6vqr/y/8tOz05+zCf3tTDA6XX3ECFsXF+vhw4eZmhoymQYGBrrq6lQ1NRVVVZX+/oHeXqFA0NvRwWlp6Whqaq2qqmexaouLK/78s5THQzroB3PSb2AAAIAV8RoYkFNS2BIUAAAAkBw0MAAAAHIJGhgAAAC5BA0MAACAXIIGBgAAQC5BAwMAACCXoIEBAACQS9DAAAAAyCVoYAAAAOQSNDAAAAByCRoYAAAAuQQNDAAAgFyCBgYAAEAuQQMDAAAgl6CBAQAAkEvQwAAAAAAAAAAAAAAAAO/xf7tSsUtQeXP6AAAAAElFTkSuQmCC\n",
      "text/plain": []
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# compute max in each image individually, then show a difference \n",
    "x = reduce(ims, 'b h w c -> b () () c', 'max') - ims\n",
    "rearrange(x, 'b h w c -> h (b w) c')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fancy examples in random order\n",
    "\n",
    "(a.k.a. mad designer gallery)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASAAAADACAIAAAAr0inhAAAcZklEQVR4nO3deVwV5RrA8QcOh0V2VxBBBNww0ETF3BcwJCVxQ1FwySUpM00pjVyzul41Mb2mhomGmgtpGCjmgiiih8E9ubkgKINeU8ytBOG9fzw4H+89hyMH58wM8Lx/ffvkx86888CvA3NmTBjPFzoDFDo7QyGBQBAXwDHGOMYYRyAQRIcJFYxAoIIRCNUSwHieZzzPM4KRkPZbGmLyjMkI77beCDsHO4S5hTnCuYkzol9IP8TyuOWIvKd5SjgcgkGgghEIVLDqg+t/X0eMmTIGYWpqigCAV4GLmwtix6EdSjhSQmVABSMQqGCKx7Un1xAdunTgxeiVHqhUKsSKjSuUcOwEPaCCEQhUMMUjNDyUN3K4tKFWqxF7ju1RwiYQtEEFIxCoYEpF8qlkXvJwaaNdx3ZK2A2CNqhgBAIVTKkYNXEUr4CCCUjNTlXCthAEUMEIBCqYUuHu6c4rIFwCYpbEKGFbCAKoYAQCFUypEH4TpZCCjY0aq4RtIQigghEIVDCF4cqjK7wCeqWNQSMHKWF/CAKoYAQCFUxhKCgrQJiZmfEKCJeAyHcjlbA/BAFUMAKBCqZUuLq78goIl4A5X85RwrYQBFDBCAQqmFIx8p2RvALCJSBFk6KEbSEIoIIRCFQwpSLpRBKvgHD5tPdBCD/eVMj+EKhgBAIVTPEICQvhJQ+X8Fu4xLREJWwCQRtUMAKBCqZ4XH18FdHevz1v5HAJtwoWbluvkE0gaIMKRiBQwaoPhFv8CrfrEOve9MKDV3488KMSjpRQGVDBCAQqWHXGkYtHEBM/nIho7dsaYWdf/nwwtXn5J6OdXJwQgQMCEUvXL0UIz21RyHERK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gDahgBAIVTGxQwQjSgApGIFDBxAYVjCANqGAEAhVMbFDBCNKACkYgUMHEBhWMIA2oYAQCFUxsUMEI0oAKRiBQwcQGFYwgDahgBAIVTGxQwQjSgApGIFDBxAYVjCANqGAEAhVMbFDBCNKACkYgUMEIhOoJKhiBQAUjEKon/gtm9DQ0+lYL4QAAAABJRU5ErkJggg==\n",
      "text/plain": []
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# interweaving pixels of different pictures\n",
    "# all letters are observable\n",
    "rearrange(ims, '(b1 b2) h w c -> (h b1) (w b2) c ', b1=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASAAAADACAIAAAAr0inhAAAkBUlEQVR4nO2deVxNW/vAV6dBM5WkUChjIg1SQiRNhKIolHhRXJdruNc1ZLjX7JrdixtKhhBFKimaFFIqVCppOI3SXKfxnN8f/a6Pl9prnWPtM9x3fT8+/shznr1aznm+Z++99rPEOKWlgNAzZeqCHoGQQyaIErEUDkfQYxBqDFIFPQIhh0wQJWLEYNSQAg2BTBAlxGAQSIGGQCaIEmIwCAIp0LlZudf+vhYfHc8sZLawWlRUVfQM9Gzm2DgtdpKUkhTAgCggBqOEGAwCKdAQyARRQgwGgc8Fuq21zWeDz5VzV9hs9rf/OkBzwPHLxydNm8TXMVFDDEYJMRgEUqAhkAmihBgMAj8LdAurxXmG88vElxQx4uLiR32POrs7821UEIjBKCEGg0AKNAQyQZQQg0HgZ4Fe47bm7rW70DBJScnbT24bTzLmw5DgEINRQgwGgRRoCGSCKCEGg8C3Ap2WnGY3wQ4xWN9YP+xFGK3jQYUYjBJiMAikQEMgE0QJMRgEvhXozSs3X71wFT0+MjVyzPgx9I0HFWIwSojBIJACDYFMECXEYBD4VqDNdMwK3hegx28/tN17szdtw0GGGIwSYjAIpEBDIBNECTEYBL4VaC0prfb2dvR4D2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IyXjRcKL9JfphfmFpcWljfWNrGaWmJiYvKK8gqJC3359hw4fqj1CW2ekzvgJ4zUGcbFTFNcI4QQJEwIw2GcKsrNTYmOzU1OLcnNLP3xorKtjNTWx2WwZOTlZefn+mpqaw4cP09MzmDp15PjxDNq+BFIjJL3piyuKHz17lJqdmpGbUVReVNtQ29jcKN1LWkFWYaDawFFDRhmOMrQxsxmhxdfyDABf92huaGh+9So7LS3n7dv3xcUVJSWVlZXVzc0tra3tbW3t4uIMKSlJaWmpPn0U+vbto6amMmSIho7OID29YcbGo+XkUBuz40XwBhNySIGGQCaIEkEaTCQQEoMJL3w0mChCDAaBFGgIZIIoIQaDQAwGgRiMEmIwCKRAQyATRAkxGARiMAjEYJQQg0EgBRoCmSBKiMEgEINBIAajhBgMAinQEMgEUUIMBoEYDAIxGCXEYBBIgYZAJogSYjAIxGAQiMEoIQaDQAo0BDJBlBCDQSAGg0AMRgkxGARSoCGQCaKEGAwCMRgEYjBKiMEgkAINgUwQJcRgEIjBIBCDUUIMBoEUaAhkgighBoNADAaBGIwSYjAIpEBDIBNECTEYBGIwCMRglBCDQSAFGgKZIEqIwSAQg0EgBqOEGAwCKdAQyARRQgwGgRgMAjEYJcRgEEiBhkAmiBJiMAjEYBCIwSghBoNACjQEMkGUEINBIAaDQAxGCTEYBFKgIZAJooQYDAIxGARiMEqIwSCQAg2BTBAlxGAQiMEgEINRQgwGgRRoCGSCKCEGg0AKNAQyQZQQg0EgBRoCmSBKiMEgkAINgUwQJf8HSGtQ5WUDKuQAAAAASUVORK5CYII=\n",
      "text/plain": []
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# interweaving along vertical for couples of images\n",
    "rearrange(ims, '(b1 b2) h w c -> (h b1) (b2 w) c', b1=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASAAAABgCAIAAAAyz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Yi9GtIvBHcihHKJRKped++y3twoUMgQAlwdnSxubjadPCZ8/2Gz78zU/fBVCzioU2QI/NZQFLDn/636l7Vndw18GTR09WVVT1eMsgz0ELpy2MnBjZfdLVSQDzhTDVoHsEeEXF06SkC2lpWVeu5LW3/3H+rUqRHFVV+RMmjJw8+UNlkfWYnz3aENhrhEIAqKyuzi0szCssvF9eXvX0aZVQ2NDYCKamPDc3t/79ffz9A0NCfIcONfhzKZhBAEhl4nQPlQTGA96bd8nl8vzb+Tcu38i7lfe4/DGrkTXwnYFBA4PGjhg7wP2Nb08/ANRqKbqOWKxa2u1rLC21loKrVYG9lagnMIqeogcjBgpFf6ECo1AIQgVGoRCECoxCIQgVGIVCECowCoUgVGAUCkGowCgUglCBUSgEoQKjUAhCBUahEIQKjEIhCBUYhUIQKjAKhSBUYBQKQajAKBSC0IRLCoUg9A1GoRDk/wF27L5xqijrrwAAAABJRU5ErkJggg==\n",
      "text/plain": []
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# interweaving lines for couples of images\n",
    "# exercise: achieve the same result without einops in your favourite framework\n",
    "reduce(ims, '(b1 b2) h w c -> h (b2 w) c', 'max', b1=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASAAAACQCAAAAACNVemdAAAP60lEQVR4nO1de1wVVR7/EspTBL0iKj5I07AwQE1dH0Q+MB9omZlWaqtZtruZUm61WZq2a/lCbSs1TbT10cesRF1TizQzFRQfSKKAigYieEVEXoKyf5y5986ZuTPnzJ25C9H9/nPumfM7vzn3N2dmfmfm952fWw204YpGea3Qqr+rU0Zhwz36VdxdHdUuclaxfkV1Em76Z1DcZgDolNjYiPHUwxl0cjMA4Nxq3ZrqJPQb6KBQHtCtqU5Cv4FKhfKWbk11EvoN1E4o79WtqU5Cv4GGmAAAbuN1a6qT0G8gv3VBADz+1U//YOoi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Qb4Yf34x4TY8eE3SkSM/fPGP/t6S+DLpXWwMiQtdQoKyzKMyASCUxa55n8xijrsY9a3VwyRa1aRMh6pqS/hQM8h/XE4CtfxyFf0JSn9FLGELmfLEkeT0XWzADQCItJ5oFcn3Sf5FLfLFepFbtlmZa6KPL8aTX4zcssyV1j5R0qNcm3yxPqRQJu/o5Itx5Bcj8TGXJitTymqTLxZCCmWGpV6+GDu/WH9yxp2ZFDq0v/2n57XJFxOiDZ3HF2PnFxu1XYgkz8hY0uWxGDvxj7XJFxNi0ZR9Xb18MXZ+Mc9FtiC0tIVDZsljnus3X4ydX6xVwnDbgrZ617gVfyy+GEd+Mf/3No205Qer/mzOH4kvxpdfrOO7e+OHW9967txKtxrBF3NafjG9fDHe/GIeUVF3Und/R+bbyscpmxjIFzM+v5hevpiG/GLuD8/aRmhT12migBF8MaflF9PJF+PIL3boou23aRop6cWtEXwxp+UXc5Qvxp9fbO2TE9ZZH4Cl25Mwgi/mvPxiDvLF+POLZSE9fXmL0Ja+KDefFTgm9JfGjOCLOS+/mKN8Md78YoXFAJCfL97WlCYoGsIXc15+MQP4Ymr5xeyNdDxN9zGEL+a8/GL6+WKq+cXsHPzoZ+m6MXwx5+UX08sXU88v1rWPNAHdCwucwhdzYn4xR/hi3PnFwpbveCXUthDo8OK2l6X21MwXU4JSfjEjYhTV+GIUOPKLyWMUi8/l3bjt5hnQsqO97G71KwyYI79YLYQB12+4DMSAy0AMuAzEgMtADLgMxIDLQAzUL76YE/KL/Q9r2I1LYrOrYgAAAABJRU5ErkJggg==\n",
      "text/plain": []
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# color can be also composed into dimension\n",
    "# ... while image is downsampled\n",
    "reduce(ims, 'b (h 2) (w 2) c -> (c h) (b w)', 'mean')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMAAA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wtGztbf1Cdka4dcTqBfLkB3jftH4OBAQAuiA3UfOOAoV+AdqUG2J/4KdxsB2DTvhgib6j7LTwmO4PBn2Hcbg893POexEffxOptbTX5oUftQ5ni+U3W8hQAdUGBsuqBhD3Wp1IAktbXHdKJNQszAdKqfpQfgeCHleF7cELRztYciZ90Gx1xePx606I4Pcjf2a+anyFoEtNB4G9X0LhE/JNuwzlYe6LX4TNlaWKkD/4zFNAvuP8295MmS8xhCiTkTCmJDY3ZPIUiXXwRDcFgkHNKfpHNSfzvDcydvxjKlkG28rR/Ac8vJ3W92+bJAAAAAElFTkSuQmCC\n",
      "text/plain": []
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# disproportionate resize\n",
    "reduce(ims, 'b (h 4) (w 3) c -> (h) (b w)', 'mean')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAkAAAAAwCAAAAADcTJoCAAAMpklEQVR4nNVd6XMUxxV/e6+u1S5CJxISuhFIGGGDuWxuhyuxk/iI7SROVeIPtqucb/4j/C2pJK5UUonLVT5SBhtsBEZgF4e4QUZYSGJ1rCQkVqtrtbs69px8kED9Zqd7ZntmxfL7pDfd87q35/Xr1++9bukmQBpnb1AKpPG2I6HqYsz+haR+W6SK2UO4Pyap9zJI6qiTINYeTJz5fzwEUfaqRI0vXASR+W7iTbD6DwAfxghi/b7E+QMAXGyhlaQ/1ShuUQp6WkE4sY5EEqv+2GFQywD9YItUDfQwweFUArMW/Lft0VFKZi79o3lOnoGRVpCgREQTqx6H8dsuXyStoGqN6i+7RCCnv/Qooodqx0cCFvLzxqjVZLDB0TRNKYre6txRL/c+VYCWFNHT/xYAINDd3XKg9HF3RhmQoEvOthBJmJLZF2CsJLIof/viTZr4zTT175eZ0dSGE5QsVYoj8tktYeFP3xd31HBaOqDxCUnVQA+TMFG14m/e9cdGqny3fyGzj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pAju6yXOOdk0pE07kgrbux0Gpjfg6Dq1nmH0nIgXW/Rl0IMtM6pY1BaAL0D1ygAzxgkimWgtPmisIWz1cCbP4Po4t4ryZrYjq5mmBhXocgnRxMUFBiuteLh50AXKRRHl8cv1KMpXSzdX44wNOOPJycBDQiSfTenF5Fcoi8GidkqvfjEi+CYzCv3OfcKkxugANkYSEkaYnzyum6KkJKrBpyHP50RgyICrjNyNViNJ8hlWj9cfLdX8TPm4x87+jcoFPCVAFaBqlj0md7CCTBFP11AQNRnQpKM/o4ysQa+Ir4FVScwEy40v1uOIxVaJkIucn/22dla5KBXUbj0XiXzJsAjLlKYdMcqB4BAjbnBKnx7GS4zRRGShFRpiP54qpjNoO0ZOR02dKq6sSyR+mChDrVqp4zEaflP9xsQDVGgiNj0XiaERGGimjiqJmIhQiZ734q+IgJ19SyvO9cdvnWF/f6dK6asXnbKhLWGICBIlqvscN+X91IQP0xSSzMpF3XlXWkSSwhuPyREC25GkCwdX016+7FN5I939caZJU5SyZ1AAAAABJRU5ErkJggg==\n",
      "text/plain": []
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# spilt each image in two halves, compute mean of the two\n",
    "reduce(ims, 'b (h1 h2) w c -> h2 (b w)', 'mean', h1=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAkAAAABgCAIAAAB6y1p+AAAjmUlEQVR4nO2dZ1wU19fHh85SFVGKNAHFAooiwYqKAiJNpVkR0b+KJZhgb4hojBgiscQWTRRjR1EUFUFBxApIUaQqvYmILLDAwu7zgjy47t6ZbbO7M3C/n3kBZ+7cOY7Lnrn3nt+5UszKSgSCTpWOJO8eEhRy8veTrJZK5n//XymPU+bZz+vs7GSzixvJPiDCAx8PNmPSJe0BwYEPCBNpSTsAwSI5IRnt1MRpE8PPhMvJyYnTHwgEAiEOMIARmvKScoyz3ku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ASUVORK5CYII=\n",
      "text/plain": []
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# split in small patches and transpose each patch\n",
    "rearrange(ims, 'b (h1 h2) (w1 w2) c -> (h1 w2) (b w1 h2) c', h2=8, w2=8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAkAAAABgCAIAAAB6y1p+AAAmt0lEQVR4nO2dd1RUVxPAZ2kiHVTK0hQpCiKGBUECKEHEBipWRAVsqLFFjeZT1FgSA7G3aKxY0GBD7CgKUWywIkQREBUEFlA0SG+77/vjwoZE2X27vLe7wP2dnD2T531zZ9/hvNm5c+8Mg+BwANMyhQbSnH3d0nV34+7eenoLAFjGLFt726MXj0rToM+R7gOSefDjEYz9E2lbIOPgByQQBWkbgPkCdbV1Sp2UAGD/1v38i4X5hYX5hUhOvJP4tcfX0jEOg8FgZAM5aRuA+QK5r3ORoKGlgTwZAGw9tDW3tvE69l4YDAaDHZjM8b95//Po44HkstKyuto6JC+ZscTFwkV6dmEwGIxsgR2YDFFTXeP7tW/EbxE8Ho/JYDIZTHSdLxe8LTBWMI6KiGr+rxgMBtMxwQ5Mhlg6c2ny/WTBY7hc7vezvpeMPRgMBiPLYAcmKzxNenoh8oLQYRyCk1uX28+xH4fA20cxGEyHBjswWeHkgZNkhiUlJgHA06Snz1Ke0WwRBoPByDQMfA5MMJI8xyNqWksmgjB80Ekg+PEIBh9zEgJ+QALBERgGg8Fg2iTYgUkfF3OXqsoq8uFXaHgoAIz2H02jTRgMBiPzYAcmfQreFnRW6aygQLYqSn5OPgBoaGrQaRQGg8HIOjgHJgScAxMCTvIIBD8eweAUjxDwAxIIjsBkDt+JvmSGkY/YMBgMpl2CHZj0cerhBADsh2z0vzF/xAgev3LTSlt729y6XNotw2AwGBkG/4qXPq6ergDAcmaRHO822M3BxYHBYNBpFAaDwcg6OAKTP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H1haRxCaOlshr8p3TFi70nDAByRqWlopN64qGX31l5eqK5JWbNnXAlpWfk5qcyq9PzzJmWWk2/iS06WrjbNbYWW3HTzuunLsiHfswssG5/ft/CglBsoeOjnPTcsUwI6NgFxckpycn877U1aGNIlIOjGAT+l300efhi4fnhzX2qdEaqKXg2LiLwXGq47Q102iyVgbZufN0SEhjuTIDgyGamo3FnxQV+6uqfo1kJ6dpvr7fITk+nl1ZKUILYjrAEZgQ8C9oIeAHJBD8eAQj+w0tpQyOwAQizQgMg8FgqMLB2oH/KRQGi1H0oQh90mwXhkawA8NgMBhMmwQ7MAwG0x4QOwdGs10YGsEODIPBYDBtEuzAMBhMewDnwDog2IFhMBgMpk2CHRgGg2kP4BxYBwQ7MAwGg8G0SbADw2Aw7QGcA+uAYAeGwWAwmDYJdmAYDKY9gHNgHRDswDAYDAbTJsEODIPBtAf+kwMj2AS/Yu/nMs5+tQ+wA8NgMBhMmwQ7MAwG0x4gmf1C4OxX+wA7MAwGg8G0Sf4P46CRotVork8AAAAASUVORK5CYII=\n",
      "text/plain": []
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# stop me someone!\n",
    "rearrange(ims, 'b (h1 h2 h3) (w1 w2 w3) c -> (h1 w2 h3) (b w1 h2 w3) c', h2=2, w2=2, w3=2, h3=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASAAAADACAIAAAAr0inhAAAfE0lEQVR4nO2dd1gUV/fHZ+kLu1SlNylCUBRBXxUVrCgWNBYssRJLLFFjiSYaiBr1VeMrRizRSKKiEcWCKCgBA0bQSBFQkWYBliYoZYFd2u7vD/MjSFm23LPsyvk8Pj6Ps3e+9zg7352ZO/eeQ+MXFlKQFBmByoN3YEQVgerj8RGMvB8fBVB1BOnmKHV1AEg7ZD/PvvDLhb+i/2Llsrgcrl5PPUdnxwlTJ8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X197twJBGU/VsjP5GiFczJhQSnM5GhJMuXcakt+Ts6NX38NDwoqFroymKaOzjhvb68lS/oOHtzqI5eOz/6iyCIej3c69HRIVEhadpowHTlYOaz2Xr1o8qJ/H1qck/Pyii9fjrp5815cXGpDQ6OQMbdEUVHByclu0qThn346ysnJruVHbY8PWYifP1LuAA3WCQJOoNcZGUmxsRnJyXnZ2YWvXlVXVnJqang8Hl1DQ53BMDQ3N+/d29bR0dnd3X7AgI5uLwUbzFDvnwtdfkn+Hw//SM5ITstOyyvOq2BXVNdWq6mqMdWZpgamn/T6xOUTlwmuE+ws7FqrtPgC2Ozax48zUlKynj17kZ9fUlDw5s2bd7W13Lq6hvr6BkVFBRUVZTU1FW1tZo8e2gYGer16GdvYmDk62g4a5NB8wyz88SGCvBsMK1yKj6W9vaW9vXT6MjMw85nq4zPVRxIRJlPdzc3ZzQ3WEkhL8BkMQQBBgyEIIGgwBAEEDYYggKDBEAQQNBiCAIIGQxBA0GAIAggaDEEAQYMhCCBoMAQBBA2GIICgwRAEEDQYggCCBkMQQNBgCAKI/C24HOgw8MOCEtBLXmEhXhwDkSnwCoYggPwfhVwH3MTBa54AAAAASUVORK5CYII=\n",
      "text/plain": []
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rearrange(ims, '(b1 b2) (h1 h2) (w1 w2) c -> (h1 b1 h2) (w1 b2 w2) c', h1=3, w1=3, b2=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAkAAAABgCAIAAAB6y1p+AAAs10lEQVR4nO2deVxN6R/HP6dNRUlI3SRLZI9uDbI2su/GvoVBxj78MIMsYxuMsRuGsTTE2GcYe8hYSt3IEIWppJMsoWiv8/vjuKfnPreSlntvPO/Xa76vb5977vXc253O+Z7P83wfCDzPCzyLn2T0D/OnFK/pXgLP13eqT+nmFuYCzxuVMaJ0m6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KHh06AJg3bRql+6xfD8DvAL0VAuMzobpaUx6xGp67dSulizdyj0dGUvrFhAQAAWptNhmlC9E/E6d7kEyZMgjA1q1zKf3kyfUAQkP3U3pc3FkAb95cpvTU1Ot2VeyoZr6je43OyLixcfbGd+9UOi7p1W3dGkCVxo0F1fvR5nXqhAaHGlartm3tNlI3sLObNGxSeUfHHm4qm9rZNm0qt5M7tmrlWF7lPrJL587VDKv1/fpreyN7Up+zfHmDSg18Dh5sXrM5qd+4ebN78+6paWlTRtD7nq1bug7A34fp3VX4mOLZlYpROL4wNATQ1sKC0rtUrQpglJsbpYsbpuxR6wscFhwM5ZaJjM+ENmPaVKzoXr179Vq1VCYdWLS1aNZshIGrQc+e35J6uVblpk5dZdPRZsMGlT+IrsNdL11SjJg/4t07lf1X1+1bByA8upT1nSogue4HpoOR3A9MzIsLg/v//BMHxN++Hac6Dy4xIiLOBhmPH8fZADlzaJEZExNnA5s4UHrszZu56sGnT+eqL/v++8nrv7eJQ4cp/Un9i6ZNTwScMI7Dep/1pA5g6typiEO3r7pRusxORikMTXIjIwNx8H/9mvotnHryBHHYee0apS/atQtxGDZjBqXXd3FBnMocOcYnz+Xtl+EcghBnOIeAmDb72v91rvrbK2/hHLLOcx+lB/0eBOeQduZjUVZl8u3UwVOBEEd7R4CelMv4BGC3EBkMBqNUohUPrBBR9L0oD6xYYCcwBoPBYJRK2AmMwWAwSiXMA2MnMAaDwWCUStgJjMFgMEolzANjJzAGg8FglErYCYzBYDBKJcwDYycwBoPBYJRK2AmMwWAwSiXMA2MnMAaDwWCUStgJjMFgMEolzANjJzAGg8FglErYCYzBYDBKJaQHJkI6T7qjF6/vRcJOYAwGg8EolbATGIPBYJRKSA9MhHSedEcvXt+LhJ3AGAwGg1Eq+T8ECT91Z0LtKgAAAABJRU5ErkJggg==\n",
      "text/plain": []
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# patterns can be arbitrarily complicated\n",
    "reduce(ims, '(b1 b2) (h1 h2 h3) (w1 w2 w3) c -> (h1 w1 h3) (b1 w2 h2 w3 b2) c', 'mean', \n",
    "       h2=2, w1=2, w3=2, h3=2, b2=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAkAAAABgCAIAAAB6y1p+AAAZdElEQVR4nO3deVgTV7sA8EkgQFiDyk5YFGVxQwyCykWxgoJoXVvhtnXpXrX187P9eltERa17+1hRq60orb3uC+CKu7hUcWERZRUDiEBREtYEEub+YT9vP1vwzWSWDL6/P/zD5+TM+55nyJuZOXMOQSCEEEIIIYQQQq8uXx/fdevXZWVl1dXVqVSq8vLylJSUWbNmiUxEXIeGEEII/R0TU5NNmzdptBry78jl8rCwMK5jRAghhP6TmZnZlStX/rZ0PdemaZsxYwbXkSKEEEJ/8uuuXzuvXs+oW9XDhg3jOliEEEKIIAiCCAwMhFSvZ67fuM51vAghhBBBEASxbds2eAEjSdLf35/rkBFCiEtCrgNAfwgbpdvsjPDwcIYiQQghXsACZijc3Nx0au/u7s5QJAghxAtYwAyChbmFichEp49069aNoWAQQogXsIAZhObm5jZNm04fUSgVzMSCEEL8gAXMIJAEWVFRodNH5HI5Q8EghBAvYAEzFOfOntOp/dkzZxmKBCGEENJBcHAwfA79rVu3BISA65ARQgghgiAIYs+ePZDq1drWGhoaynWwCCGE0L+JxeJrv13rvHpptJpZs2ZxHSlCCCH0n8zMzLZt29bRavTl5eWvjX6N6xgRQgihDvj5+n333XfZ2dl1ijq1Wl1RUZGalvrue++amOr2rhhCCCGEEEIIIYQQQgghhBBCCCGEEEIIIcQkLldzMDUxCQoODg0NHdC/f+8+fZydnCytrExNTFpaWpqbm2trax+UlpaWlmZmZl65evVBSQmHoSJD4OTk5Onp6e7u7ubm/oydnZ25ublYLH72r1gsFggEzc3NLS0tNTU1crm8tPRBZmbmtWtXS0oecB0+2zw9PEaGhckGD+7dp0+vXr0kE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6urSksfFhcX5+bm3Lhxs7mZpbcSEUKoy9LpCozrYJG+eHBPCSGEEPorLGAIIYR4CQsYQgghXsIChhBCiJewgCGEEOIlLGAIIYR4CQsYQgghXsIChhBCiJewgCGEEOIlLGAIIYR4CQsYQgghXsIChhBCiJewgCGEEOIlLGAIIYR4CQsYQgghXsIChhBCCCGEEEIIIYQQ6sT/AcYVQkQcIYbpAAAAAElFTkSuQmCC\n",
      "text/plain": []
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# subtract background in each image individually and normalize\n",
    "# pay attention to () - this is composition of 0 axis, a dummy axis with 1 element.\n",
    "im2 = reduce(ims, 'b h w c -> b () () c', 'max') - ims\n",
    "im2 /= reduce(im2, 'b h w c -> b () () c', 'max')\n",
    "rearrange(im2, 'b h w c -> h (b w) c')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAkAAAABgCAIAAAB6y1p+AAAHqUlEQVR4nO3da0yWZRzH8cDAlIWKOqfTWogulUmJhyIrjwyXK0zTjQ1Ly6zNzUxlHgg7mFKbsDSbbUi9YEllS9HpcjayTWalKIomhqAioskansoopFe9+93Eza675/nr9/PyO3bdl4/Gv3u79lwRrfX1d8HbhX7Brl9VWSV7wQcFsi9fs1z2uN5xzvbkS9AfkHEX+XjaNKI81DsIc3xAbYoM9QYAAOgIBhgAwCQGGADAJAYYAMAkBhgAwKS7Q72BO13hhkLZPyv4TPahSUNln7NgjrM9AYAFvIEBAExigAEATGKAAQBMYoABAExigAEATOIUYog9MOgBXz8fPyg+oJ0AgC28gQEATGKAAQBMYoABAExigAEATGKAAQBMiuBG5rYFfuFwq84N5xtk7zugb4Cb6QBuZG4TNzK3jQuH/wMfUJt4AwMAmMQAAwCYxAADAJjEAAMAmMQAAwCYFPh3IRZs2SL7ytxc2f+4eVP2V2fPlj135UrZI9qxt//TzIkzZb988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6odPK4UdfLrZZbAe3kdhER6g0EonuvXrJfvnDByfqXzp/39dw7TWNTo+zdYvQN8uHG6/dMQUGO7IsXZ8q+Zk2h7EVFu2TftGmr7FlZ+oZ0v3gDAwCYxAADAJjEAAMAmMQAAwCYxAADAJjk7BTioyNHyr51507Zz9TVyT75iSdkP1VbK3sf46ekevTU30HnZX/pftmPHdI3wzb91iT745Mf9/VchFbSY4/J/u1XX8m+q6hI9r+am2U/XVkp+/hp09qxO3u+L/9e9vKT+gZqr5uXUx9JdbanIBUXfyN7Q4M+XTlunP59PmPGRNm9TiHW1V1qx+46jjcwAIBJDDAAgEkMMACASQwwAIBJDDAAgEnOTiEuW7BA9pJv9OmXrNWrnTw37803ZR+VlORk/aDF3KtvJh2erG84rThYIXvayDTZBw8dLHvp8dJ27A7hYvYSfRPud19/Lfsbmfq77LxERur/l830eK51c9+a62SdzKf8fc6hUlZ2VPYNG4oDfe7YsQ8Fuj5vYAAAkxhgAACTGGAAAJMYYAAAkxhgAACTnJ1CHJGYKHvpVn0j53sbN8pec+6c7Pf16yf7SCOnDf3KL8yXfdXrq2S/fvW67Gnp+nRiuHnwQf3vZ+rU52Tv2lWf3uzcOdrXOomJD7djd6GXOGaM7Ou2b5f909xc2VtbW2WfvXSp7EkpKe3YnT3PTnhW9pr6GtnTx6XLnpGW4WpLgZo/X/95m5quyV5RcUr22Fj9311GxhTZZ86c3I7ddRxvYAAAkxhgAACTGGAAAJMYYAAAkxhgAACTIlrr60O9h7B2QR9+xL/4gNp0kY+nTSP0Bci+rfhwhexrP1kre/X2atkH9h/oZkOuuPqAblO8gQEATGKAAQBMYoABAExigAEATGKAAQBMYoABAExigAEATGKAAQBMYoABAExigAEATGKAAQBMcnYjMwCESmKCvtH7uUn6Ju6YLvpmYdjCGxgAwCQGGADAJAYYAMAkBhgAwCQGGADApH8AHKGN3Tu3+7MAAAAASUVORK5CYII=\n",
      "text/plain": []
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# pixelate: first downscale by averaging, then upscale back using the same pattern\n",
    "averaged = reduce(ims, 'b (h h2) (w w2) c -> b h w c', 'mean', h2=6, w2=8)\n",
    "repeat(averaged, 'b h w c -> (h h2) (b w w2) c', h2=6, w2=8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAkAAAABgCAIAAAB6y1p+AAAehklEQVR4nO3de1xNWd8A8N3penTPpaILKmFqRBJKrkklIXIZRDOT6wwPGYNnJMS4vZgyPIyMy+SWSy5FiiKEioqoDrpLovs5Xc95/2hez7ym9lrnnHX2Pqf5fT/zx6S111q2c/Zv77XX+i0lUUkJBdr31pjtHsg5OEG04PTQG5TGdg/kHJwgWhy2OwAAAABIAgIYAAAAhQQBDAAAgEKCAAYAAEAhQQADAACgkCCAAQAAUEgQwAAAACgkCGAAAAAUEgQwAAAACgkCGAAAAIUEAQwAAIBCggAGAABAIUEAAwAAoJAggAEAAFBIEMAAAAAoJAhgAAAAFBIEMAAAAAoJAhgAAACFBAEMAACAQoIABgAAQCFBAAMAAKCQIIABAABQSBDAAAAAKCQVtjtAURT17v37lzxeXmFhXmFhRVUVXyAQ1NdTFNWJy+VqaHQxMDA3MelpavqFtbWBnh7bnZXc26K39AWMTYyZ6Qn4hxAKha+fP3/++HFBbm5pfv67oiJ+bW09n9/c1KSuoaHO5Wrp6hqamBiZmfXq16+fvb1Znz5KSkps9xoAXKwFsKrq6kvXr8cmJt5PSckrLMQ8qk/v3sMdHLxcXT3GjtVQV5dpD4mzN7WnL1AiKmGmJ6Bjq/rwISEqKuHSpZTbt/m1tfgHaunqDnV1HeHl5eLlpaOvL7seAkCEkqiE6YvmraSk0PDwmFu3GhobJa5EW0vL18tr1aJF/aysCPbt796SeyjqrtSdvoBCBjCCJ6gjYvj0ZDx4cCYsLD4yskmKLxdFUWoaGq7Tp89YtuyLIUNI9a1Ng9JkWr3i64g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TAdBQhgLWqqKiOjU1OT89586akurqWoig9Pe3evU0cHPqPHGmvqyuTdD8MBbBPeHl5py9duhgT8/T5c8ykU60Y7ucnCh3A/Lz8ku8k11S3uxRs5YaVgcGBUrWh0CdI9pg8PU2NjdEnT0YeOJCVIu3TBofDGTZhgu+SJbKebcjk9blF2HI58XJ4VHjMvZgWIWL9KJKulu7EERP9vf1HDx4tw9e0ihPAWMF0APukqro66dGj1IyMrJycF7m5xaWlHysraW6fIYBJrLS4NCcrJycrJ/dFbuv/VHyooChKVU31cf7jbkbSLXjoACdIllg5PdlPnty6cOHOlSs5GInW/kpZRcXO2dnFy2usj4+xOXqPY+mxcn1+X/E+Njk2Njn23tN7r4tf4z+1a3fSdvjCYfiA4aMHjx4xcISqiuyzDkEAo8VaAPu7pqam9x8/1vH59fX1DY2NFEWpqampqapqdupkoKfH1q7KHfL6/OH9h5ysnLraOgIzODrkCSKH3dNTWV6elZKSlZJSyOOVFhSUFRUJ6urq+fymxkZ1LleDy9XS1TU0NTUyM+vZt+8XDg7WAwdymd08j/Xrcw2/5hnvWf7b/OL3xaXlpa3ZexubGtVU1dTV1DW5mt30u3Uz6GZubG5tbt2jG+P7WrB+guSbHAUw+QTXZwQ4QbTg9NCD6zMCnCBaMpxGDwAAAMgOBDAAAAAKCQIYAAAAhQQBDAAAgEKCAAYAAEAhQQADAACgkCCAAQAAUEgQwAAAACgkCGAAAAAUEgQwAAAACgkCGAAAAIUEAQwAAIBCggAGAABAIUEAAwAAoJAggAEAAFBIEMAAAAAoJAhgAAAAFBIEMAAAAAoJAhgAAACFBAEMAACAQoIABgAAQCFBAAMAAKCQIIABAABQSP8LNFzetlL/OOwAAAAASUVORK5CYII=\n",
      "text/plain": []
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rearrange(ims, 'b h w c -> w (b h) c')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png":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HVhLizmTm8z9XfDPV7P1UX60JmOboNEile+yqiRwF/NZUHag4TEH2Myme6R2By8QNxBzHDaMwDOpbZg4EFCQc0/YlRmX3kLBmB65Fc5YCnQ3IByXFgFYSnQ7IVyXNgsgaVAsxcWhVkwDRaFWSgZFoVZMASLwiyYBovCLJQMi8IsGIJFYRZMg0VhFkqGRWEWDMGiMAumwaIwCyVjaOfaLYeWcWgZh5ZtPRS9stLjKQpLgWYvthwyJ2N/WWEp0NzABvOyIJqL/wOlUg0ziG78EQAAAABJRU5ErkJggg==\n",
      "text/plain": []
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# let's bring color dimension as part of horizontal axis\n",
    "# at the same time horizontal axis is downsampled by 2x\n",
    "reduce(ims, 'b (h h2) (w w2) c -> (h w2) (b w c)', 'mean', h2=3, w2=3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ok, numpy is fun, but how do I use einops with some other framework?\n",
    "\n",
    "If that's what you've done with `ims` being numpy array:\n",
    "```python\n",
    "rearrange(ims, 'b h w c -> w (b h) c')\n",
    "```\n",
    "That's how you adapt the code for other frameworks:\n",
    "\n",
    "```python\n",
    "# pytorch:\n",
    "rearrange(ims, 'b h w c -> w (b h) c')\n",
    "# tensorflow:\n",
    "rearrange(ims, 'b h w c -> w (b h) c')\n",
    "# chainer:\n",
    "rearrange(ims, 'b h w c -> w (b h) c')\n",
    "# gluon:\n",
    "rearrange(ims, 'b h w c -> w (b h) c')\n",
    "# cupy:\n",
    "rearrange(ims, 'b h w c -> w (b h) c')\n",
    "# jax:\n",
    "rearrange(ims, 'b h w c -> w (b h) c')\n",
    "\n",
    "...well, you got the idea.\n",
    "```\n",
    "\n",
    "Einops allows backpropagation as if all operations were native to framework.\n",
    "Operations do not change when moving to another framework"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# Summary\n",
    "\n",
    "- `rearrange` doesn't change number of elements and covers different numpy functions (like `transpose`, `reshape`, `stack`, `concatenate`,  `squeeze` and `expand_dims`)\n",
    "- `reduce` combines same reordering syntax with reductions (`mean`, `min`, `max`, `sum`, `prod`, and any others)\n",
    "- `repeat` additionally covers repeating and tiling\n",
    "- composition and decomposition of axes are a corner stone, they can and should be used together\n",
    "\n",
    "\n",
    "\n",
    "- [Second part of tutorial](https://github.com/arogozhnikov/einops/tree/master/docs) shows how einops works with other frameworks\n",
    "- [Third part of tutorial](https://arogozhnikov.github.io/einops/pytorch-examples.html) shows how to improve your DL code with einops"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
